using Common.Commands;
using Common.Commands.TemplateCommands;
using Core.Domain.Model;
using Core.Infrastructure.CustomExceptions;
using Sanelib.DataOperation;
using Sanelib.Dto;

namespace Core.Processors.TempleteProcessors
{
    public class DeleteTempleteProcessor : ICommandProcessor<DeleteTemplete>
    {
        private readonly IRepository<Templete> _templeteRepository;

        public DeleteTempleteProcessor(IRepository<Templete> templeteRepository)
        {
            _templeteRepository = templeteRepository;
        }

        public dynamic Process(DeleteTemplete command)
        {
            var response = new WebApiResultResponse();

            var templete = _templeteRepository.GetById(command.Id);

            if (templete == null)
                throw new DomainProcessException("Templete not available");

            _templeteRepository.Delete(templete.Id);
            response.IsSuccess = true;

            return response;
        }
    }
}
